// /////////////////////////////////////////////////////////////////////////////
//
// Name:            TextureProcessor.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the TextureProcessor class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __TEXTUREPROCESSOR_H__
#define __TEXTUREPROCESSOR_H__

// Include files
#include "../dependencies.h"
#include "../core/AssetProcessor.h"


// TextureProcessor class
//! AssetProcessor for processing textures in an AssetGroup.
//! In order to properly reload a texture from an asset group the class that uses the texture
//! needs to implement a event method for the "textures/<filename>" event. When the texture
//! is reloaded a event will be emitted to the appropriate slot with the new texture as the
//! parameter. See SceneComponent::onTexture or ImageComponent::onTexture for an example.
class TextureProcessor : public AssetProcessor
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    TextureProcessor(AssetGroup *parent);
    //! Deconstructor
    ~TextureProcessor();

    // Public methods
    //! Gets the texture with the given filename.
    //! @param fileName      Filename of the texture.
    ITexture* getTexture(const std::string &fileName);

    //! Reloads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool reloadAsset(const std::string &fileName);
    //! Reloads all assets.
    void reloadAssets();

    //! Removes the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful removal, false otherwise.
    bool removeAsset(const std::string &fileName) ;
    //! Removes all assets.
    void removeAssets();

    //! Creates a new TextureProcessor.
    //! @note For internal use only!
    static AssetProcessor* createProcessor(AssetGroup *parent);

protected:

    // Protected methods
    //! Loads the asset with the given filename.
    //! @param fileName      Filename of the asset.
    //! @return True on succesful loading, false otherwise.
    bool loadAsset(const std::string &fileName);
    //! Loads all assets.
    void loadAssets();


private:

    // Private members
    std::map<std::string, ITexture*> mTextures;

    bool mIsReloading;
};

#endif
